package priv.pront.code.robot.roboCom_pri_2021.zhi.fu;

import java.io.*;
import java.util.*;

/**
 * @Description:
 * @Author: pront
 * @Time:2023-07-13 16:26
 */
public class 人工智能刑警 {

    static BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
    static PrintWriter out = new PrintWriter(System.out);
    static int n, m, row = -1, col = -1;


    static class Info {
        public List<Info> list;
        public int no;
        public String id;

        public Info() {
            this.list = new ArrayList<>();
        }

        public Info(int no) {
            this.no = no;
            this.list = new ArrayList<>();
        }

        public Info(int no, String id) {
            this.no = no;
            this.id = id;
            this.list = new ArrayList<>();
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;
            Info info = (Info) o;
            return no == info.no;
        }

        @Override
        public int hashCode() {
            return Objects.hash(no);
        }
    }

    static Info info = new Info();

    public static void main(String[] args) throws IOException {
        String[] s = bf.readLine().split(" ");
        Info root = info;
        n = Integer.parseInt(s[0]);
        m = Integer.parseInt(s[1]);
        for (int i = 0; i < n; i++) {
            String[] ss = bf.readLine().split(" ");
            String id = ss[ss.length - 1];
            for (int j = 0; j < ss.length - 1; j++) {
                int num = Integer.parseInt(ss[j]);
                if (!info.list.contains(new Info(num))) {
                    Info info1;
                    if (j == ss.length - 2) {
                        info1 = new Info(num, id);
                    } else {
                        info1 = new Info(num);
                    }
                    info.list.add(info1);
                    info = info1;
                } else {
                    int index = info.list.indexOf(new Info(num));
                    info = info.list.get(index);
                }
            }
            info = root;
        }
        bf.readLine();
        while (true) {
            String[] sss = bf.readLine().split(" ");
            if (sss[0].equals("0")) break;
            for (int i = 0; i < sss.length; i++) {
                int num = Integer.parseInt(sss[i]);
                if (info.list.contains(new Info(num))) {
                    Info info11 = info.list.get(info.list.indexOf(new Info(num)));
                    info = info11;
                    if (i == sss.length - 1) {
                        out.println(info11.id);
                        out.flush();
                    }
                } else {
                    out.println("Pass");
                    out.flush();
                    break;
                }
            }
            info = root;
        }

        out.close();
    }
}
